<template>
  <div>
    <div class="create_box">
      <el-button type="primary" :disabled="judgePermission('jurisdiction')" @click="openCreateClick()">
        <el-icon>
          <Plus />
        </el-icon>
        <span class="create_text">管理成员</span>
      </el-button>
    </div>
    <div class="table_box">
      <el-table v-loading="pageLoading" :data="TableData" class="tableClass" ref="multipleTable" tooltip-effect="dark"
        style="width: 100%" :highlight-current-row="true">
        <el-table-column label="姓名">
          <template #default="scope">
            <div class="table_NameBox">
              <!-- <img v-if="scope.row.objectType == '3'" style="background: #3662EC;" src="@/assets/images/jues.png"
                alt="" />
              <img v-if="scope.row.objectType == '2'" style="background: #FE4D4F;" src="@/assets/images/gwei.png"
                alt="" />
              <img v-if="scope.row.objectType == '1'" style="background: #07b9b9;" src="@/assets/images/bumeng.png"
                alt="" /> -->
              <div v-if="scope.row.objectType == '0'" class="avatar">
                <div>{{ scope.row.objectName.slice(0, 1) }}</div>
              </div>
              <div>{{ scope.row.objectName }}</div>
            </div>
          </template>
        </el-table-column>

        <el-table-column prop="objectTypeText" label="维度">
          <template #default="scope">
            <div>{{ scope.row.objectTypeText }}</div>
          </template>
        </el-table-column>
        <el-table-column label="权限">
          <template #default="scope">
            {{ scope.row.roleName }}
          </template>
        </el-table-column>

        <el-table-column prop="createTime" label="加入时间"></el-table-column>
      </el-table>
      <div style="margin-top: 5px;">
        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
          :current-page="requestStr.page" :page-sizes="[10, 20, 30, 40]" :page-size="requestStr.size"
          layout="total,  prev, pager, next,sizes" :total="requestStr.total">
        </el-pagination>
      </div>
    </div>
    <!-- 团队的添加成员 -->
    <el-dialog v-model="dialogVisible" title="选择成员" width="550" :before-close="handleClose">
      <team-new-user ref="SelectMemberNewTeamRefs" :pageType="'team'"
       ></team-new-user>
      <template #footer>
        <div class="dialog-footer">
          <!-- <el-button @click="dialogVisible = false">Cancel</el-button> -->
          <el-button type="primary" @click="dialogVisible = false">
            关闭
          </el-button>
        </div>
      </template>
    </el-dialog>
    <!-- <team-new-user ref="SelectMemberNewTeamRefs" :pageType="'team'"
      @closeClick="selectMemberNewTeam_closeClick"></team-new-user> -->

  </div>
</template>

<script lang="ts" setup>
import { apiTeamRelevanceRoleQuery } from "@/api/teamKnowdge/teamDocApi"
import { useTeamRoleStore } from '@/store/modules/teamRole'
import TeamNewUser from "@/views/teamKnowdge/power/index.vue"
const teamRoleStore = useTeamRoleStore()
const { proxy } = getCurrentInstance() as any
const pageLoading = ref(false)
const SelectMemberNewTeamRefs = ref(null)
const TableData = ref([])
const dialogVisible = ref(false)
const requestStr = reactive({
  page: 1,
  size: 10,
  total: 0,
})
const fileDetailInfo = ref({
  id: null,
  teamId: "",
})

const props = defineProps({
  pageType: {
    type: String,
    // self:个人,team:团队,enterprise:企业
    default: "",
  },
})
const openCreateClick = () => {
  dialogVisible.value = true
  nextTick(() => {
    SelectMemberNewTeamRefs.value.getTableData(fileDetailInfo.value.teamId, fileDetailInfo.value)
  })
}

const getTableList = async (row) => {
  if (row) {
    fileDetailInfo.value = row
  }
  console.log(fileDetailInfo.value, '123')
  let requestParams = {
    page: requestStr.page - 1,
    size: requestStr.size,
    sort: "id,asc",
    treeNodeId: fileDetailInfo.value.id,
  }
  pageLoading.value = true
  const res = await apiTeamRelevanceRoleQuery(requestParams)
  if (res.code == 200) {
    pageLoading.value = false
    requestStr.total = res.data.total
    TableData.value = res.data.rows
    TableData.value.forEach((item) => {
      let objectTypeText
      switch (item.objectType) {
        case 0:
          objectTypeText = '用户'
          break
        case 1:
          objectTypeText = '部门'
          break
        case 2:
          objectTypeText = '岗位'
          break
        case 3:
          objectTypeText = '角色'
          break
        default:
          objectTypeText = '未知'
      }
      // 将新属性添加到对象中
      item.objectTypeText = objectTypeText
      return item
    })
  }
}
const judgePermission = (str) => {
  // return !this.$yuUtils.documentsPermissionFunc([str], this.myTeamFIleRoleList);
  return !proxy.$yuUtils.documentsPermissionFunc([str], teamRoleStore.myTeamFileRoleList)
}

const handleSizeChange = (val) => {
  requestStr.size = val
  getTableList(fileDetailInfo.value)
}
const handleCurrentChange = (val) => {
  requestStr.page = val
  getTableList(fileDetailInfo.value)
}


defineExpose({
  getTableList
})





</script>






<style scoped lang="scss">
.table_box {
  :deep(th) {
    color: #666;
    font-weight: normal;
    font-size: 14px;
    height: 51px;
  }

  :deep(tr) {
    color: #333;
    height: 51px;
  }

  :deep(.el-table__body tr:hover .realName_box_right) {
    visibility: visible;
  }
}

.create_box {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 6px;
  margin-right: 5px;

  :deep(.el-button--primary) {
    background-color: #6698ff;
    border-color: #6698ff;
  }

  :deep(.el-button--primary:focus) {
    box-shadow: 0 2px 5px 1px rgba(102, 152, 255, 0.6);
  }

  :deep(.el-button--primary:hover) {
    box-shadow: 0 2px 5px 1px rgba(102, 152, 255, 0.6);
  }

  .el-button--primary.is-disabled {
    color: #fff !important;
    background-color: #94b7fd !important;
    border-color: #94b7fd !important;

    &:hover {
      box-shadow: none !important;
    }
  }
}

.table_NameBox {
  display: flex;
  align-items: center;

  .avatar {
    width: 24px;
    height: 24px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 12px;
    background-color: #56abfb;
    margin-right: 4px;

    span {
      transform: scale(0.9, 0.9);
    }
  }

  img {
    padding: 2px;
    width: 22px;
    height: 22px;
    margin-right: 5px;
    border-radius: 15px;
  }
}
</style>